package com.heima.admin.service.impl;

import com.alibaba.fastjson.JSON;
import com.heima.admin.service.WmNewsArtificialService;
import com.heima.api.admin.IAdminClient;
import com.heima.api.admin.IUserClient;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.IsPassDto;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.pojos.WmNews;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class WmNewsArtificialServiceImpl  implements WmNewsArtificialService {

    private final IUserClient iUserClient;

    private final IAdminClient wemediaClient;


    @Override
    public PageResponseResult list(NewsAuthDto dto) {
        //获取文章列表
        PageResponseResult list = wemediaClient.findList(JSON.toJSONString(dto));
        String str = (String) list.getData();
        List<WmNews> records = JSON.parseObject(str, List.class);
        PageResponseResult result = new PageResponseResult();
        result.setData(records);
        result.setCurrentPage(dto.getPage());
        result.setSize(dto.getSize());
        result.setTotal(list.getTotal());

        return result;
    }

    /** 查询文章 */
    @Override
    public ResponseResult findOne(Integer id) {
        ResponseResult result = wemediaClient.findOne(id);
        return result;
    }

    /** 通过 */
    @Override
    public ResponseResult pass(IsPassDto dto) {
        wemediaClient.isPass(JSON.toJSONString(dto));
        return ResponseResult.okResult(null);
    }
}
